<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属灯杆">
              <j-search-select-tag
                placeholder="请选择所属灯杆"
                v-model="queryParam.lightPoleId"
                dict="tb_light_pole,light_name,id"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入设备名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属项目">
                <j-search-select-tag
                  placeholder="请选择所属项目"
                  v-model="queryParam.projectId"
                  dict="tb_project,project_name,id"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleHistoryData(record)">气象数据</a> -->
          <a @click="handleSee(record)">查看</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)" style="margin-left: 10px">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <camera-modal2 ref="modalForm" @ok="modalFormOk"></camera-modal2>
    <camera-modal ref="modalForm2"></camera-modal>
    <PlayerModal ref="PlayerDialogRef" :footer="null"></PlayerModal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CameraModal2 from './modules/CameraModal2'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import CameraModal from './CameraModal'
import PlayerModal from './playerModal'
export default {
  name: 'CameraList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CameraModal2,
    CameraModal,
    PlayerModal,
  },
  data() {
    return {
      seeVisible: false,
      description: '气象管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '所属灯杆',
          align: 'center',
          dataIndex: 'lightPoleId_dictText',
        },
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '设备型号',
          align: 'center',
          dataIndex: 'deviceModel',
        },
        {
          title: '设备编号',
          align: 'center',
          dataIndex: 'deviceCode',
        },
        {
          title: '端口号',
          align: 'center',
          dataIndex: 'ep',
        },
        {
          title: '所属项目',
          align: 'center',
          dataIndex: 'projectId_dictText',
        },
        {
          title: '所属分组',
          align: 'center',
          dataIndex: 'groupId_dictText',
        },
        {
          title: '在线状态',
          align: 'center',
          dataIndex: 'olStatus_dictText',
        },
        {
          title: '开关状态',
          align: 'center',
          dataIndex: 'onStatus_dictText',
        },
        {
          title: '设备状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '所属云盒mac地址',
          align: 'center',
          dataIndex: 'mac',
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/corp/cam/list',
        delete: '/corp/cam/delete',
        deleteBatch: '/corp/cam/deleteBatch',
        exportXlsUrl: '/corp/cam/exportXls',
        importExcelUrl: 'corp/cam/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.$set(this.dictOptions, 'olStatus', [
      { text: '是', value: 'Y' },
      { text: '否', value: 'N' },
    ])
    this.$set(this.dictOptions, 'onStatus', [
      { text: '是', value: 'Y' },
      { text: '否', value: 'N' },
    ])
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    handleHistoryData(record) {
      //弹出天气数据  更加deviceId 查出列表 （设备管理- 实时走势）
      this.$refs.modalForm2.open(record)
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({
        type: 'sel_search',
        value: 'lightPoleId',
        text: '所属灯杆id',
        dictTable: 'tb_light_pole',
        dictText: 'light_name',
        dictCode: 'id',
      })
      fieldList.push({ type: 'string', value: 'name', text: '设备名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceId', text: '设备id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceModel', text: '设备型号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'deviceCode', text: '设备编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'ep', text: '端口号', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'projectId',
        text: '所属项目id',
        dictTable: 'tb_project',
        dictText: 'project_name',
        dictCode: 'id',
      })
      fieldList.push({
        type: 'sel_search',
        value: 'groupId',
        text: '所属分组id',
        dictTable: 'tb_group',
        dictText: 'group_name',
        dictCode: 'id',
      })
      fieldList.push({ type: 'switch', value: 'olStatus', text: '在线状态:0.掉线; 1.在线' })
      fieldList.push({ type: 'switch', value: 'onStatus', text: '开关状态：0.关; 1 开' })
      fieldList.push({
        type: 'string',
        value: 'status',
        text: '设备状态: 0.禁用; 1. 启用; 2.报警',
        dictCode: 'device_status',
      })
      fieldList.push({ type: 'string', value: 'mac', text: '所属云盒mac地址', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      this.superFieldList = fieldList
    },
    /**
     * @method 查看
     * @param record {Object}
     */
    handleSee(record) {
      this.$refs.PlayerDialogRef.open(record)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>